package com.karry.yl.web.baseinfo;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.karry.commons.base.SuperController;
import com.karry.commons.vo.JsonResponse;
import com.karry.commons.vo.LayTableResponse;
import com.karry.yl.domain.baseinfo.BedType;
import com.karry.yl.service.baseinfo.BedTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 床位类型信息Controller
 *
 */
@Controller
@RequestMapping("/bedtype")
public class BedTypeController extends SuperController {

    @Autowired
    private BedTypeService bedTypeService;
    /**
     * 到床位类型列表页
     * @return
     */
    @RequestMapping
    public String listUI(){
        return "baseinfo/bedtype/list";
    }
    @RequestMapping("/list")
    @ResponseBody
    public LayTableResponse listUI(int page, int limit){
        Page<BedType> bedTypePage = bedTypeService.selectPage(new Page<BedType>(page, limit),new EntityWrapper<BedType>().eq("orgId",currentUser.getOrgId()));
        return new LayTableResponse(bedTypePage.getRecords(),bedTypePage.getTotal());
    }
    @RequestMapping("/add")
    public String addUI(){
        return "baseinfo/bedtype/add";
    }
    @RequestMapping("edit")
    public String editUI(Long id, ModelMap map){
        BedType bedType = bedTypeService.selectById(id);
        map.put("bedType",bedType);
        return "baseinfo/bedtype/edit";
    }
    @RequestMapping("/save")
    public String save(BedType bedType){
        bedType.setOrgId(currentUser.getOrgId());
        bedTypeService.insert(bedType);
        return "redirect:/bedtype";
    }

    @RequestMapping("/update")
    public String update(BedType bedType){
        bedType.setOrgId(currentUser.getOrgId());
        bedTypeService.updateById(bedType);
        return "redirect:/bedtype";
    }

    /**
     * 删除
     * @param
     * @return
     */
    @RequestMapping("/delete")
    public String delete(Long id){
        bedTypeService.deleteById(id);
        return "redirect:/bedtype";
    }

    @RequestMapping("/selectBedTypeList")
    @ResponseBody
    public JsonResponse selectBedTypeList() {
        List<BedType> bedTypes=bedTypeService.selectList(new EntityWrapper<BedType>().eq("orgId", currentUser.getOrgId()));
        return JsonResponse.success(bedTypes);
    }
}
